package dao.impl;

import dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;
import util.MyBatisUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserDaoimpl implements UserDao {


    @Override
    public List<User> findAll() {
        /*//引入 mybatis 的配置文件
        String resource = "mybatis-config.xml";
        SqlSession sqlSession=null;
        try {
            InputStream resourceAsStream = Resources.getResourceAsStream(resource);
            //创建会话工厂
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
            sqlSession = sqlSessionFactory.openSession();
            return sqlSession.getMapper(UserDao.class).findAll();
        }  catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
                sqlSession.close();
        }*/

        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll();
    }
}
